package com.itheima.servlet;

import com.itheima.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 祺诺
 * @Name; xqf
 * @Date: 2020/12/28 14:51
 */
@WebServlet("/LoginStudentServlet")
public class LoginStudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        User user  =new User(username,password);
        if("zhangsan".equals(username)&&"123".equals(password)){
            req.getSession().setAttribute("user",user);
            resp.sendRedirect(req.getContextPath()+"/index.jsp");
        }else{
            req.setAttribute("smg","账号密码错误请重新登录");
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
